#pragma once
#include "ECS.h"

namespace ECS
{
	// Some automatics stuff for 
	// caching components
	template <class TComponent>
	class Dependent : public Component
	{
	public:
		Dependent() : _cachedComponent(nullptr) {}
		
		template <class TDependency>
		TDependency* getDependency() const;

		// Specialization (only available)
		template <>
		TComponent* getDependency() const
		{
			if (_cachedComponent == nullptr)
				_cachedComponent = getComponent<TComponent>();

			return _cachedComponent;
		}
	private:
		mutable TComponent* _cachedComponent;
	};

	template <class TComponent1, class TComponent2>
	class Dependent2 : public Component
	{
	public:
		Dependent2() : _cachedComponent(nullptr) {}

		template <class TDependency>
		TDependency* getDependency() const;

		// Specialization (only available)
		template <>
		TComponent1* getDependency() const
		{
			if (_cachedComponent1 == nullptr)
				_cachedComponent1 = getComponent<TComponent1>();

			return _cachedComponent1;
		}
		template <>
		TComponent2* getDependency() const
		{
			if (_cachedComponent2 == nullptr)
				_cachedComponent2 = getComponent<TComponent2>();

			return _cachedComponent2;
		}
	private:
		mutable TComponent1* _cachedComponent1;
		mutable TComponent2* _cachedComponent2;
	};
}